home *** CD-ROM | disk | FTP | other *** search
/ Aminet 12 / Aminet 12 (1996)(GTI - Schatztruhe)[!][Jun 1996].iso / Aminet / dev / lang / HeliOS3.lha / helios_demo_disk3 / source / AttachedHSpriteFromIFF.src next >
Encoding:
Text File  |  1995-11-11  |  14.6 KB  |  549 lines

  1.  
  2.   \ ***********************************************************
  3.   \
  4.   \       ATTACHED HARDWARE SPRITE FROM IFF IMAGERY DEMO
  5.   \
  6.   \ ***********************************************************
  7.   \
  8.   \ This code demonstrates how to create a simple HeliOS single
  9.   \ playfield display and generate an attached hardware sprite
  10.   \ using bitmapped imagery derived from an IFF ILBM file.
  11.   \
  12.   \ One IFF file is loaded as the display backdrop picture and
  13.   \ another IFF is loaded as imagery for the hardware sprite.
  14.   \
  15.   \ The hardware sprite is moved around the screen using the mouse.
  16.   \
  17.   \ Press <Space> to quit when finished.
  18.   \
  19.   \ ***********************************************************
  20.  
  21.  
  22.   \ ***********************************************************
  23.   \ Re-initialise HeliOS dictionary to standard CORE vocabulary
  24.   \ ***********************************************************
  25.  
  26.   \ This should always be used at the start of any program which
  27.   \ is to be repeatedly recompiled.
  28.  
  29.   FORGET **CORE**
  30.  
  31.   \ *************************
  32.   \ Load include symbol files
  33.   \ *************************
  34.   \
  35.   \ These "include files" are pre-compiled (for speed) versions of the
  36.   \ Amiga includes and the Helios system includes.
  37.   \
  38.   \ Uncomment the lines below for standalone compilation, but otherwise
  39.   \ it is better to set these include files from the Helios Forth menus
  40.  
  41.   AMIGAINCLUDE HeliOS:HeliOS_AmigaInclude
  42.   USERINCLUDE  HeliOS:HeliOS_UserInclude
  43.  
  44.   \ ****************************************
  45.   \ Create display imagery file name strings
  46.   \ ****************************************
  47.  
  48.   \ These files are ordinary IFF's (and may be "PowerPacked" if required)
  49.   \
  50.   \ The pictures here will be loaded into each of the display BitMaps.
  51.   \
  52.  
  53.   $CONSTANTL Slice1Pic $Helios:Source/Data/Pic2$
  54.  
  55.   \ **************************************
  56.   \ Create display configuration constants
  57.   \ **************************************
  58.   \
  59.   \ Collect all "display-specific" parameters here and generate "named"
  60.   \ constants which make references easier than using numeric values.
  61.   \
  62.   \ Collecting these together here makes it easier to adjust things at any
  63.   \ time without having to search source code to replace values individually.
  64.   \
  65.  
  66.  
  67.   256                      CONSTANT DisplayHeight      \ Full PAL display
  68.   320                      CONSTANT DisplayWidth       \ Lores display
  69.   44                       CONSTANT DisplayTopLine     \ Display start
  70.  
  71.   DisplayWidth             CONSTANT Slice1Width        \ Lores width
  72.   DisplayWidth 32 +        CONSTANT Slice1RasterWidth  \ Raster=screenwidth
  73.   DisplayHeight            CONSTANT Slice1Height       \ Slice height
  74.   DisplayHeight 32 +       CONSTANT Slice1RasterHeight \ Slice Raster=Displayheight
  75.   0                        CONSTANT Slice1Mode         \ Lores
  76.   3                        CONSTANT Slice1Planes       \ Slice bitplanes
  77.  
  78.   \ The calculation below takes the number of bitplanes and calculates
  79.   \ how many colours this represents.
  80.   \
  81.   \ One bitplane gives two colours.
  82.   \
  83.   \ Each additional bitplane multiplies the number of colours by two.
  84.   \
  85.   \ Performing a single LSL operation on any number multipies by 2, so we
  86.   \ have a quick method of multiplying by two for our colour calculation.
  87.   \
  88.   \ In this case, we need "2 to the power 3", which is 2*2*2=8.
  89.   \
  90.   \ e.g.                              2*2*2
  91.   \                                   ^ ^ ^
  92.   \                                   Total number of planes = 3
  93.   \
  94.   \
  95.   \ So, we take the first value two
  96.   \
  97.   \ e.g.                              2*2*2
  98.   \                                   ^
  99.   \                                  Initial start value of 2
  100.   \
  101.   \ and we now need to multiply it by two "the_number_of_planes minus_one"
  102.   \ more times.
  103.   \
  104.   \ e.g.                              2*2*2
  105.   \                                     ^ ^
  106.   \                                     Total planes minus one
  107.   \
  108.   \
  109.   \ So, Number of colours = 2 operated on by LSL NumberOfPlanes-1 times.
  110.   \
  111.  
  112.   2 Slice1Planes 1- LSL    CONSTANT Slice1Colours      \ A-slice colours
  113.  
  114.   \ ***********************
  115.   \ Error handling routines
  116.   \ ***********************
  117.  
  118.   \ This error handler allows all errors to be routed via a comprehensive
  119.   \ sequential closedown routine, which is associated with the HeliOS
  120.   \ system error handler word ERROR".
  121.   \
  122.   \ When ERROR" senses an error, it prints an associated error message
  123.   \ delimited by '"' characters, and then closes everything down using the
  124.   \ routine CLOSEDOWN below which you have supplied.
  125.   \
  126.   \ This simplifies errors checks to the use of a single word, ERROR", which
  127.   \ displays a text message and closes eveything down.
  128.   \
  129.  
  130.   0 VARIABLE (CLOSEDOWN)
  131.  
  132.   : ?CLOSEDOWNERROR
  133.  
  134.   IF
  135.     CR
  136.     CR
  137.     TYPE
  138.     CR
  139.     CR
  140.     ." Press <Space> to quit!"
  141.     CR
  142.     CR
  143.     WAITSPACE
  144.     (CLOSEDOWN) @EXECUTE
  145.     QUIT
  146.   ELSE
  147.     DDROP
  148.   THEN
  149.   ;
  150.  
  151.   LATESTCFA VARIABLE ERROR1
  152.  
  153.   \ ****************************************
  154.   \ Create display pointer storage variables
  155.   \ ****************************************
  156.  
  157.   \ Here we create a set of "pointers", initially set to a "null" value.
  158.   \
  159.   \ These "pointers" are set up as "long addresses" when various components
  160.   \ of the display system are allocated and initialised.
  161.   \
  162.   \ Note that initially these are all set to zero, and we clear them back
  163.   \ to zero when we de-allocate the associated resource.
  164.   \
  165.   \ These DPOINTERs are all initially set to "null" by using '0.'.
  166.   \
  167.   \ When we allocate memory or Amiga system resources in the program at
  168.   \ run-time, these pointers are updated to contain the 32-bit address
  169.   \ of the newly allocated resource.
  170.   \
  171.   \ Subsequently the symbolic DPOINTER name can be used in your code to
  172.   \ represent the associated address.
  173.  
  174.   0. DPOINTER Display1             \ Main Display structure pointer
  175.   0. DPOINTER Slice1               \ Slice 1 Slice structure pointer
  176.  
  177.   0. DPOINTER Slice1_ColorMap      \ Slice 1 ColourMap structure pointer
  178.  
  179.   0. DPOINTER Slice1_RasInfo       \ Slice 1 RasInfo structure pointer
  180.  
  181.   0. DPOINTER Slice1_BMap          \ Slice 1 BitMap structure pointer
  182.  
  183.   0. DPOINTER Slice1_SliceControl  \ Slice 1 SliceControl structure pointer
  184.  
  185.   \ *************
  186.   \ Colour tables
  187.   \ *************
  188.  
  189.   \ Each colour entry requies 2 bytes of storage space
  190.  
  191.   CREATEL Slice1_ColorTable        \ Create longword pointer to table
  192.   Slice1Colours 2* 0 ALLOTFILL     \ Allocate Slice1 colours * 2 bytes
  193.  
  194.   \ ***********************************
  195.   \ Create Display and Slice structures
  196.   \ ***********************************
  197.  
  198.   \ This routine simply makes blank structures, which then need to be
  199.   \ initialised later (in the CREATE_DISPLAY routine).
  200.  
  201.   : CREATE_DSLICES
  202.  
  203.   DS_SIZEOF MAKESTRUCTURE Display1 MAKEPOINTER  \ Main "Display" structure
  204.  
  205.   SL_SIZEOF MAKESTRUCTURE Slice1   MAKEPOINTER  \ Display "Slice" structure
  206.   ;
  207.  
  208.   : FREE_DSLICES
  209.  
  210.   Slice1    DDUP FREEMEMORY   CLEARPOINTER
  211.   Display1  DDUP FREEMEMORY   CLEARPOINTER
  212.   ;
  213.  
  214.   \ ******************************
  215.   \ Create RasInfo structures etc.
  216.   \ ******************************
  217.  
  218.   : CREATE_RASINFO
  219.  
  220.   \ First allocate and initialise complete RasInfo structures.
  221.   \
  222.   \ This routine automatically allocates all BitMaps etc.
  223.   \
  224.  
  225.   Slice1RasterWidth Slice1RasterHeight Slice1Planes  OPENRASINFO
  226.   DFLAG0= ERROR" Fail: RasInfo1"
  227.   Slice1_RasInfo MAKEPOINTER
  228.  
  229.   \ Set invisible area "sprite margins" for slice RasInfo
  230.  
  231.   16              Slice1_RasInfo         ri_RxOffset    INDEX!L
  232.   16              Slice1_RasInfo         ri_RyOffset    INDEX!L
  233.  
  234.   \ Store BitMap pointer - often useful for later reference
  235.  
  236.   Slice1_RasInfo  ri_BitMap INDEXD@L Slice1_BMap MAKEPOINTER
  237.   ;
  238.  
  239.   : FREE_RASINFO
  240.  
  241.   Slice1_RasInfo   DDUP CLOSERASINFO   CLEARPOINTER
  242.   ;
  243.  
  244.   \ ********************************
  245.   \ Create Display/Slice Copperlists
  246.   \ ********************************
  247.  
  248.   \ This function builds the main display copperlist by:
  249.   \
  250.   \ 1. Initialising the Slice data structure
  251.   \ 2. Calling MAKECOPSTRIP for the slice, to build a copperlist
  252.   \ 3. Calling MAKEDISPLAY to build the master Display copperlist
  253.   \
  254.  
  255.   : CREATE_DISPLAY
  256.  
  257.   \ First initialise main display structures
  258.  
  259.   Slice1                           Display1  DS_Slice     INDEXD!L
  260.  
  261.   Slice1Width                      Slice1    SL_DWidth    INDEX!L
  262.   Slice1Height                     Slice1    SL_DHeight   INDEX!L
  263.   DisplayTopLine                   Slice1    SL_DyOffset  INDEX!L
  264.   Slice1_RasInfo                   Slice1    SL_RasInfo   INDEXD!L
  265.   Slice1_ColorMap                  Slice1    SL_ColorMap  INDEXD!L
  266.   Slice1Mode                       Slice1    SL_Modes     INDEX!L
  267.  
  268.   \ Generate copper list information for each of the display slices
  269.  
  270.   Slice1 MAKECOPSTRIP
  271.   D0= ERROR" Fail: Slice1CopStrip"
  272.  
  273.   \ Make display
  274.  
  275.   Display1 MAKEDISPLAY
  276.   D0= ERROR" Fail: Display1"
  277.   ;
  278.  
  279.   : FREE_DISPLAY
  280.  
  281.   Display1                 FREEDISPLAY
  282.   Slice1                   FREECOPSTRIP
  283.   ;
  284.  
  285.   \ ********************************************************
  286.   \ Create SliceControl structures for double buffered slice
  287.   \ ********************************************************
  288.  
  289.   \ SliceControl structures are used to control any slices which perform
  290.   \ mapping or scrolling functions, or which require double or triple
  291.   \ playfield buffering.
  292.   \
  293.   \ In this case we have one slice which does not scroll, is not mapped,
  294.   \ but IS double buffered.
  295.   \
  296.  
  297.   : CREATE_SLICECONTROL
  298.  
  299.   \ Make SliceControl for double buffered bitmap display
  300.  
  301.   Slice1  0 0 MAKESLICECONTROL
  302.   DFLAG0= ERROR" Fail: SliceControl1"
  303.   Slice1_SliceControl MAKEPOINTER
  304.  
  305.   \ Install slice controls into HeliOS display control system
  306.  
  307.   Slice1_SliceControl  INSTALLSLICECONTROL
  308.   ;
  309.  
  310.   : FREE_SLICECONTROL
  311.  
  312.   CLEARSLICECONTROLS
  313.   Slice1_SliceControl  CLOSESLICECONTROL
  314.   ;
  315.  
  316.   \ These routines load an IFF picture into supplied BitMap, and correctly
  317.   \ initialises the supplied ColorTable.
  318.   \
  319.   \ The ColorTable is then used to create an initialised ColorMap structure.
  320.   \
  321.  
  322.   : CREATE_IMAGERY
  323.  
  324.   Slice1_BMap
  325.   Slice1_ColorTable
  326.   Slice1Pic
  327.   10 2 DOSLIB                        \ Call to internal HeliOS library
  328.   10 <> ERROR" Fail: Slice1Pic"
  329.  
  330.   Slice1_ColorTable  Slice1Colours MAKECOLORMAP  \ Allocate ColourMap
  331.   DFLAG0= ERROR" Fail: Slice1ColorMap"
  332.   Slice1_ColorMap MAKEPOINTER
  333.   ;
  334.  
  335.   : FREE_IMAGERY
  336.  
  337.   Slice1_ColorMap  DDUP FREECOLORMAP  CLEARPOINTER
  338.   ;
  339.  
  340.   \ ***********************************
  341.   \ Create hardware sprite colour table
  342.   \ ***********************************
  343.  
  344.   \ This colour table simply specifies a few arbitrary colours which we
  345.   \ will then set into colour registers 16 to 31
  346.  
  347.   CREATEL MySpriteColourTable
  348.  
  349.   HEX
  350.  
  351.   0000 ,  \ Colour 16
  352.   0FFF ,  \ Colour 17
  353.   0CC0 ,  \ Colour 18
  354.   0F00 ,  \ Colour 19
  355.   0AAA ,  \ Colour 20
  356.   0999 ,  \ Colour 21
  357.   0888 ,  \ Colour 22
  358.   0777 ,  \ Colour 23
  359.   0666 ,  \ Colour 24
  360.   0555 ,  \ Colour 25
  361.   0444 ,  \ Colour 26
  362.   0333 ,  \ Colour 27
  363.   0222 ,  \ Colour 28
  364.   0111 ,  \ Colour 29
  365.   00F0 ,  \ Colour 30
  366.   000F ,  \ Colour 31
  367.  
  368.   DECIMAL
  369.  
  370.   \ ***********************
  371.   \ Allocate pointer stores
  372.   \ ***********************
  373.  
  374.   0. DPOINTER  MyHSpriteData1
  375.   0. DPOINTER  MyHSpriteData2
  376.  
  377.   CREATEL MYFILE $ HeliOS:Source/Data/16ColourHSTestBrush$
  378.  
  379.   \ MAKEATTHSPRITE  ( - - - HSpriteData1(l), HSpriteData2(l) )
  380.   \                         or null for failure
  381.  
  382.   : MAKEATTHSPRITE
  383.  
  384.   MYFILE  2 3 DOSLIB
  385.   2 =
  386.   IF
  387.     D>R                       \ Save BitMap pointer
  388.     1 2                       \ IDs
  389.     1                         \ Number of images
  390.     DI                        \ BitMap
  391.     5 5                       \ X and Y offsets
  392.     9 9                       \ Width and height
  393.     MAKEATTHSPRITEBLOCK_BMAP  \ Make HSprite definition blocks
  394.     DR> CLOSEBMAP             \ Restore BitMap pointer and close BitMap
  395.   ELSE
  396.     0.
  397.     0.
  398.   THEN
  399.   ;
  400.  
  401.   \ **********************
  402.   \ Set up hardware sprite
  403.   \ **********************
  404.  
  405.   \ First we set sprite colours 16 to 31
  406.   \ Then we create hardware sprite definition blocks
  407.   \ Then we install the hardware sprites
  408.  
  409.   : SetupHSprite
  410.  
  411.   Slice1 MySpriteColourTable 16 16 SETSLICECOLOURS
  412.  
  413.   MAKEATTHSPRITE
  414.   DFLAG
  415.   IF
  416.     MyHSpriteData2 MAKEPOINTER
  417.     MyHSpriteData1 MAKEPOINTER
  418.  
  419.     MyHSpriteData1 0 HSPRITE_INSTALL
  420.     MyHSpriteData2 1 HSPRITE_INSTALL
  421.     0
  422.   ELSE
  423.     DDDROP
  424.     1
  425.   THEN
  426.   ;
  427.  
  428.   \ **************************
  429.   \ Close down hardware sprite
  430.   \ **************************
  431.  
  432.   \ First we remove the hardware sprites
  433.   \ Then we de-allocate the sprite definitions
  434.  
  435.   : FREE_HSPRITE
  436.  
  437.   MyHSpriteData1 HSPRITE_REMOVE
  438.   MyHSpriteData2 HSPRITE_REMOVE
  439.  
  440.   MyHSpriteData2  DDUP FREEHSPRITEBLOCK  CLEARPOINTER
  441.   MyHSpriteData1  DDUP FREEHSPRITEBLOCK  CLEARPOINTER
  442.   ;
  443.  
  444.   \ ********************************
  445.   \ Display and move hardware sprite
  446.   \ ********************************
  447.  
  448.   \ Switch on mouse position reporting
  449.   \ Switch off the HeliOS mouse pointer image
  450.   \ Repeatedly set the sprite to the current mouse pointer position
  451.  
  452.   : TestHSprite
  453.  
  454.   1 REPORTMOUSE
  455.   0 HELIOSMPOINTER
  456.  
  457.   BEGIN
  458.     0 MOUSEX MOUSEY 0 MyHSpriteData1 HSPRITE_PLACE
  459.     1 MOUSEX MOUSEY 0 MyHSpriteData2 HSPRITE_PLACE
  460.     ?TERMINAL 32 =
  461.   UNTIL
  462.   ;
  463.  
  464.  
  465.   \ *********************
  466.   \ Close down everything
  467.   \ *********************
  468.  
  469.   : CLOSEDOWN
  470.  
  471.   FREE_HSPRITE
  472.   FREE_SLICECONTROL
  473.   FREE_DISPLAY
  474.   FREE_IMAGERY
  475.   FREE_RASINFO
  476.   FREE_DSLICES
  477.   RESETERROR"
  478.   ;
  479.  
  480.   LATESTCFA (CLOSEDOWN) !
  481.  
  482.   : TestDisplay          \ Start of program
  483.  
  484.   SCRCLR
  485.  
  486.   CR
  487.   ."        **********************************************************"
  488.   CR 6 FPENSET
  489.   ."              ATTACHED HARDWARE SPRITE FROM IFF IMAGERY DEMO"
  490.   CR 1 FPENSET
  491.   ."        **********************************************************"
  492.   CR
  493.   CR
  494.   ."        This code demonstrates how to create a simple HeliOS single"
  495.   CR
  496.   ."        playfield display and generate an attached hardware sprite"
  497.   CR
  498.   ."        using bitmapped imagery derived from an IFF ILBM file."
  499.   CR
  500.   CR
  501.   ."        One IFF file is loaded as the display backdrop picture and"
  502.   CR
  503.   ."        another IFF is loaded as imagery for the hardware sprite."
  504.   CR
  505.   CR
  506.   ."        The hardware sprite can then be moved around using the mouse."
  507.   CR
  508.   CR
  509.   ."        Press <Space> to quit demo."
  510.   CR
  511.   CR
  512.   ."        **********************************************************"
  513.   CR 6 FPENSET
  514.   ."                  Press <Space> or <L-Mouse> to see Demo          "
  515.   CR 1 FPENSET
  516.   ."        **********************************************************"
  517.   CR
  518.  
  519.   WAITSPACE
  520.  
  521.   SCRCLR
  522.  
  523.   ERROR1 SETERROR"       \ Redirect system errors to our routine ERROR1
  524.  
  525.   CREATE_DSLICES
  526.   CREATE_RASINFO
  527.   CREATE_IMAGERY
  528.   CREATE_DISPLAY
  529.   CREATE_SLICECONTROL
  530.  
  531.   SetupHSPrite ERROR" Failed to open HSprite!"
  532.  
  533.   HeliOS_On
  534.  
  535.   1 FrameRate !L
  536.  
  537.   Display1 SHOWDISPLAY
  538.  
  539.   TestHSprite
  540.  
  541.   HeliOS_Off
  542.  
  543.   0 REPORTMOUSE
  544.  
  545.   CLOSEDOWN
  546.   ;
  547.  
  548.   TestDisplay
  549.